package com.xcjh.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xcjh.domain.DataAcquisition;
import com.xcjh.dto.jiyuan.JiayuanData;
import com.xcjh.eums.AppType;
import com.xcjh.service.DataAcquisitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/check")
public class JiayuanController {

    @Autowired
    private DataAcquisitionService dataAcquisitionService;

    @PostMapping(value = "/checkJ")
    public String show(HttpServletResponse response, @RequestBody List<String> body) throws Exception {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Method", "POST,GET");


        if (CollectionUtil.isEmpty(body)) {
            return "";
        }

//    	String in="167381244,163630278,165260124,179204195,179060345,168720740,158349036,167371661,157999747,167377373,167038234,161167753,167450249,158636623,159933090,165677681,163453381,157228597,164376767,159805297,156522301,164502147,165618603,167973597,168351801,";
//        if (in.lastIndexOf(",") == (in.length() - 1) && !StringUtils.isBlank(in)) {
//            in = in.substring(0, in.length() - 1);
//        }
        List<Long> data = dataAcquisitionService.lambdaQuery().in(DataAcquisition::getAppId, body)
                .eq(DataAcquisition::getType, AppType.JIAYUAN.getMessage())
                .list().stream().map(d->Long.parseLong(d.getAppId()))
                .collect(Collectors.toList());
        if (!data.isEmpty()) {
            System.out.println("重复：" + data);
        }
        return CollUtil.join(data, ",");
    }


}
